


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > BoardFactory</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">nl.tudelft.jpacman.board</a>
</div>

<h1>Coverage Summary for Class: BoardFactory (nl.tudelft.jpacman.board)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">BoardFactory</td>
<td class="coverageStat">
  <span class="percent">
    20%
  </span>
  <span class="absValue">
    (1/5)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    5.3%
  </span>
  <span class="absValue">
    (1/19)
  </span>
</td>
</tr>
  <tr>
    <td class="name">BoardFactory$Ground</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$1447885123</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$1447885123$auxiliary$2lfvMYIy</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$1447885123$auxiliary$E7dpQVG0</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$1447885123$auxiliary$J5W8hxB5</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$1447885123$auxiliary$pdxLYVHQ</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$MockitoMock$1447885123$auxiliary$tsX5ASxD</td>
  </tr>
  <tr>
    <td class="name">BoardFactory$Wall</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/3)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    0%
  </span>
  <span class="absValue">
    (0/5)
  </span>
</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    9.1%
  </span>
  <span class="absValue">
    (1/11)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    3.4%
  </span>
  <span class="absValue">
    (1/29)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package nl.tudelft.jpacman.board;
&nbsp;
&nbsp;import nl.tudelft.jpacman.sprite.PacManSprites;
&nbsp;import nl.tudelft.jpacman.sprite.Sprite;
&nbsp;
&nbsp;/**
&nbsp; * A factory that creates {@link Board} objects from 2-dimensional arrays of
&nbsp; * {@link Square}s.
&nbsp; *
&nbsp; * @author Jeroen Roosen 
&nbsp; */
<b class="fc">&nbsp;public class BoardFactory {</b>
&nbsp;
&nbsp;    /**
&nbsp;     * The sprite store providing the sprites for the background.
&nbsp;     */
&nbsp;    private final PacManSprites sprites;
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new BoardFactory that will create a board with the provided
&nbsp;     * background sprites.
&nbsp;     *
&nbsp;     * @param spriteStore
&nbsp;     *            The sprite store providing the sprites for the background.
&nbsp;     */
<b class="nc">&nbsp;    public BoardFactory(PacManSprites spriteStore) {</b>
<b class="nc">&nbsp;        this.sprites = spriteStore;</b>
<b class="nc">&nbsp;    }</b>
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new board from a grid of cells and connects it.
&nbsp;     *
&nbsp;     * @param grid
&nbsp;     *            The square grid of cells, in which grid[x][y] corresponds to
&nbsp;     *            the square at position x,y.
&nbsp;     * @return A new board, wrapping a grid of connected cells.
&nbsp;     */
&nbsp;    public Board createBoard(Square[][] grid) {
<b class="nc">&nbsp;        assert grid != null;</b>
&nbsp;
<b class="nc">&nbsp;        Board board = new Board(grid);</b>
&nbsp;
<b class="nc">&nbsp;        int width = board.getWidth();</b>
<b class="nc">&nbsp;        int height = board.getHeight();</b>
<b class="nc">&nbsp;        for (int x = 0; x &lt; width; x++) {</b>
<b class="nc">&nbsp;            for (int y = 0; y &lt; height; y++) {</b>
<b class="nc">&nbsp;                Square square = grid[x][y];</b>
<b class="nc">&nbsp;                for (Direction dir : Direction.values()) {</b>
<b class="nc">&nbsp;                    int dirX = (width + x + dir.getDeltaX()) % width;</b>
<b class="nc">&nbsp;                    int dirY = (height + y + dir.getDeltaY()) % height;</b>
<b class="nc">&nbsp;                    Square neighbour = grid[dirX][dirY];</b>
<b class="nc">&nbsp;                    square.link(neighbour, dir);</b>
&nbsp;                }
&nbsp;            }
&nbsp;        }
&nbsp;
<b class="nc">&nbsp;        return board;</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new square that can be occupied by any unit.
&nbsp;     *
&nbsp;     * @return A new square that can be occupied by any unit.
&nbsp;     */
&nbsp;    public Square createGround() {
<b class="nc">&nbsp;        return new Ground(sprites.getGroundSprite());</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * Creates a new square that cannot be occupied by any unit.
&nbsp;     *
&nbsp;     * @return A new square that cannot be occupied by any unit.
&nbsp;     */
&nbsp;    public Square createWall() {
<b class="nc">&nbsp;        return new Wall(sprites.getWallSprite());</b>
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * A wall is a square that is inaccessible to anyone.
&nbsp;     *
&nbsp;     * @author Jeroen Roosen
&nbsp;     */
&nbsp;    private static final class Wall extends Square {
&nbsp;
&nbsp;        /**
&nbsp;         * The background for this square.
&nbsp;         */
&nbsp;        private final Sprite background;
&nbsp;
&nbsp;        /**
&nbsp;         * Creates a new wall square.
&nbsp;         *
&nbsp;         * @param sprite
&nbsp;         *            The background for the square.
&nbsp;         */
<b class="nc">&nbsp;        Wall(Sprite sprite) {</b>
<b class="nc">&nbsp;            this.background = sprite;</b>
<b class="nc">&nbsp;        }</b>
&nbsp;
&nbsp;        @Override
&nbsp;        public boolean isAccessibleTo(Unit unit) {
<b class="nc">&nbsp;            return false;</b>
&nbsp;        }
&nbsp;
&nbsp;        @Override
&nbsp;        public Sprite getSprite() {
<b class="nc">&nbsp;            return background;</b>
&nbsp;        }
&nbsp;    }
&nbsp;
&nbsp;    /**
&nbsp;     * A ground square is a square that is accessible to anyone.
&nbsp;     *
&nbsp;     * @author Jeroen Roosen
&nbsp;     */
&nbsp;    private static final class Ground extends Square {
&nbsp;
&nbsp;        /**
&nbsp;         * The background for this square.
&nbsp;         */
&nbsp;        private final Sprite background;
&nbsp;
&nbsp;        /**
&nbsp;         * Creates a new ground square.
&nbsp;         *
&nbsp;         * @param sprite
&nbsp;         *            The background for the square.
&nbsp;         */
<b class="nc">&nbsp;        Ground(Sprite sprite) {</b>
<b class="nc">&nbsp;            this.background = sprite;</b>
<b class="nc">&nbsp;        }</b>
&nbsp;
&nbsp;        @Override
&nbsp;        public boolean isAccessibleTo(Unit unit) {
<b class="nc">&nbsp;            return true;</b>
&nbsp;        }
&nbsp;
&nbsp;        @Override
&nbsp;        public Sprite getSprite() {
<b class="nc">&nbsp;            return background;</b>
&nbsp;        }
&nbsp;    }
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-04-23 16:26</div>
</div>
</body>
</html>
